cc.Class({
    extends: cc.Component,

    properties: {
    },

    // use this for initialization
    onLoad: function () {
        this.ani = this.node.getComponent(cc.Animation);
        if(!this.ani || !this.ani.defaultClip) return;
        this.paths = this.ani.defaultClip.curveData.paths;
    },

    init: function (components, flip) {
        this.node.flip = flip;
        this.node.runAction(cc.flipX(this.node.flip));

        for (var key in components){
            if(!components.hasOwnProperty(key)) continue;
            this.setComponent(key, components[key]);
        }
    },

    setComponent: function (key, curveData) {
        if(!this.paths[key]) return;

        this.paths[key] = curveData;
        if(this.ani.isRunning()){
            //重置播放数据和时间
            this.time = this.ani.getAnimationState(this.ani.defaultClip.name).time;
            this.ani._createStates();
            this.ani.play(this.ani.defaultClip.name, this.time);
        }
    },

    resetComponent: function (key) {
        if(!this.paths[key]) return;

        //删除此部件上的spriteFrame
        cc.find(key, this.node).getComponent(cc.Sprite).spriteFrame = null;
        this.paths[key].comps["cc.Sprite"].spriteFrame = [];

        //重置播放数据和时间
        this.time = this.ani.getAnimationState(this.ani.defaultClip.name).time;
        this.ani._createStates();
        this.ani.play(this.ani.defaultClip.name, this.time);
    },

    isComponentExist: function (key) {
        if(!this.paths[key]) return false;
        return this.paths[key].comps["cc.Sprite"].spriteFrame.length > 0;
    },

    //角色 方向
    //部件 方向
    //
    export: function () {
        var modelData = {
            "flip": this.node.flip ? 1 : 0,
            "commpnents": {
                "handLeft":     1002,
                "handRight":    2003,
                "footLeft":     4002,
                "footRight":    5003,
                "head":         6002,
                "body":         7002,
                "basic":        8002,
            }
        }
    },

    // called every frame, uncomment this function to activate update callback
    update: function (dt) {
    },
});
